home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Subject: Re: Hungarian notation
- Date: 30 Jan 1996 13:15:41 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4em1ptINNn1@keats.ugrad.cs.ubc.ca>
- References: <30C40F77.53B5@swsbbs.com> <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca> <4e5k6o$aci@grid.direct.ca> <4ej0ds$sju@rational.rational.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4ej0ds$sju@rational.rational.com>,
- Bob Kitzberger <rlk@rational.com> wrote:
- >qjackson@direct.ca wrote:
- >: I use typedef primarily if I know that an underlying data type might
- >: change at some point in the future, and I want to have one central way
- >: of changing it. [...]
- >...
- >: Data abstraction.
- >
- >That bears as much resemblance to data abstraction as McDonald's bears
- >to fine dining. You are using the primitive language types, and only
- >in those special cases where you believe that a type will change do
- >you introduce an alias for the type name. That is not abstraction.
-
- I fully agree. The using typedef to define a new name for a primitive type like
- long or int is nothing more than an issue of aliasing.
-
- Abstraction means more. The concept includes operations. Doing a typedef to
- rename an integer to something else doesn't hide the fact that the new type is
- still compatible with integers, and integer operators like '+', '-', '<<' and
- so on.
-
- >The term "abstraction" means to emphasize the essential aspects and
- >de-emphasize the inessential -- i.e. the user of a module (ADT, package,
- >class, etc.) sees the abstraction, and you, the implementor of
- >the module/ADT/package/class, hide the inessential details. One
- >of these inessential details is the primitive type (or types) that
- >make up the inner workings of your abstraction.
-
- Right. To make a truly abstract data type for, say, time_t, one would have to
- hide the fact that it is an integer (the inessential aspect) and provide
- abstract operations for manipulating this type, such as functions to convert
- some other date breakdwon into time_t, for calculating the difference between
- two time_t's and such.
-
- I still maintain my point that typedefs are not necessary for good coding in C.
- The aliasing for which they are useful can just as easily be accomplished with
- pre-processor macros.
-
- I use them infrequently for managing complex types with greater ease.
- There arise situations in which pre-processor macros don't "cut it". For
- example,
-
- typedef int (* compfun_t)(void *, void *)
-
- can't be done as a "#define compfun_t" macro.
-
- If you do
-
- #define compfun_t int (*)(void *, void *)
-
- You can use "compfun_t" in a cast all right, but you can use it to define
- variables of type compfun_t, since for function types, the cast form and
- declaration form don't simply differ by the presence of an identifier on the
- right.
-
- This is one case where it really behooves the C coder to avail himself of a
- typedef. :)
-
- But I will keep on writing "struct foo *bar
- --
-
-